//
//  ZLExamRecordCell.m
//  ZLExamination
//
//  Created by Zheng on 2017/8/10.
//  Copyright © 2017年 Zheng. All rights reserved.
//

#import "ZLExamRecordCell.h"
#import "ZLExamRecordModel.h"

@interface ZLExamRecordCell ()

@property (nonatomic, strong) UIImageView *thumbImgv; //缩略图
@property (nonatomic, strong) UILabel *titleLbl; //标题
@property (nonatomic, strong) UILabel *scoreLbl; //分数
@property (nonatomic, strong) UILabel *ratingLbl; //是否合格
@property (nonatomic, strong) UILabel *timeLbl; //时间

//@property (nonatomic, strong) UILabel *gotoExamLbl; //去考试
@property (nonatomic, strong) UILabel *stateLbl; //未完成

@property (nonatomic) ZLExamRecordCellStyle style;

@end

@implementation ZLExamRecordCell


- (void)setModel:(ZLExamRecordModel *)model {
    _model = model;
    
    
    _titleLbl.text = _model.title;
    
    if (_model.status.integerValue == 2) {
        //暂停
        _style = ZLExamRecordCellStyleUnFinish;
        _timeLbl.text = [YCRequestDataService timeintervalFormatYMDHMS:@(_model.suspend_time.integerValue)];
//        _gotoExamLbl.text = @"继续考试";
//        _gotoExamLbl.hidden = NO;
        _ratingLbl.hidden = YES;
        _scoreLbl.hidden = YES;
        _stateLbl.hidden = NO;
        
    } else if (_model.status.integerValue == 3) {
        //已完成
        _timeLbl.text = [YCRequestDataService timeintervalFormatYMDHMS:@(_model.end_time.integerValue)];
        
        _ratingLbl.hidden = NO;
        _scoreLbl.hidden = NO;
        _stateLbl.hidden = YES;
        
        _scoreLbl.text = [NSString stringWithFormat:@"得分: %@分",_model.result_num];
        
        if (_model.is_pass.integerValue == 1) {
            //考试合格
            _style = ZLExamRecordCellStylePass;
//            _gotoExamLbl.hidden = YES;
            _ratingLbl.text = @"合格";
            
        } else {
            //考试不合格
            _style = ZLExamRecordCellStyleUnPass;
//            _gotoExamLbl.text = @"重新考试";
//            _gotoExamLbl.hidden = NO;
            _ratingLbl.text = @"不合格";
        }
        
    } else {
        //考试中
    }
    
}

- (ZLExamRecordCellStyle)getExamState {
    return _style;
}



#pragma mark - 初始化方法
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self.contentView addSubview:self.thumbImgv];
        [self.contentView addSubview:self.titleLbl];
        [self.contentView addSubview:self.scoreLbl];
        [self.contentView addSubview:self.ratingLbl];
        [self.contentView addSubview:self.timeLbl];
//        [self.contentView addSubview:self.gotoExamLbl];
        [self.contentView addSubview:self.stateLbl];
        
        [_thumbImgv mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(15);
            make.centerY.equalTo(self);
            make.width.mas_equalTo(60);
            make.height.mas_equalTo(62.5);
        }];
        
        [_titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(_thumbImgv.mas_right).offset(15);
            make.top.mas_equalTo(15);
            make.right.mas_equalTo(-40);
        }];
        
        [_scoreLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_titleLbl);
            make.bottom.mas_equalTo(-12);
        }];
        
        [_ratingLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_scoreLbl.mas_right).offset(12);
            make.centerY.equalTo(_scoreLbl);
        }];
        
        [_timeLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(-28);
            make.left.equalTo(_titleLbl);
        }];
        
//        [_gotoExamLbl mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.right.mas_equalTo(-12);
//            make.bottom.mas_equalTo(-12);
//        }];
        
        [_stateLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_titleLbl);
            make.bottom.mas_equalTo(-12);
        }];
        
    }
    return self;
}

- (UILabel *)stateLbl {
    if (!_stateLbl) {
        _stateLbl = [[UILabel alloc] init];
        _stateLbl.textColor = [UIColor grayColor];
        _stateLbl.font = kCX_FONT(11);
        _stateLbl.text = @"未完成";
    }
    return _stateLbl;
}

//- (UILabel *)gotoExamLbl {
//    if (!_gotoExamLbl) {
//        _gotoExamLbl = [[UILabel alloc] init];
//        _gotoExamLbl.textColor = kRGB_COLOR(252, 79, 91, 1);
//        _gotoExamLbl.font = kCX_FONT(11);
//        _gotoExamLbl.hidden = YES;
//    }
//    return _gotoExamLbl;
//}

- (UIImageView *)thumbImgv {
    if (!_thumbImgv) {
        _thumbImgv = [[UIImageView alloc] init];
        _thumbImgv.image = kIMAGE(@"er_icon");
    }
    return _thumbImgv;
}

- (UILabel *)titleLbl {
    if (!_titleLbl) {
        _titleLbl = [[UILabel alloc] init];
        _titleLbl.font = kCX_FONT(13);
    }
    return _titleLbl;
}

- (UILabel *)scoreLbl {
    if (!_scoreLbl) {
        _scoreLbl = [[UILabel alloc] init];
        _scoreLbl.font = kCX_FONT(11);
        _scoreLbl.textColor = [UIColor grayColor];
        _scoreLbl.hidden = YES;
    }
    return _scoreLbl;
}

- (UILabel *)ratingLbl {
    if (!_ratingLbl) {
        _ratingLbl = [[UILabel alloc] init];
        _ratingLbl.font = kCX_FONT(11);
        _ratingLbl.textColor = [UIColor grayColor];
        _ratingLbl.hidden = YES;
    }
    return _ratingLbl;
}

- (UILabel *)timeLbl {
    if (!_timeLbl) {
        _timeLbl = [[UILabel alloc] init];
        _timeLbl.font = kCX_FONT(11);
        _timeLbl.textColor = [UIColor grayColor];
    }
    return _timeLbl;
}


@end
